using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text.RegularExpressions;
//using VmgFootball.Data.Business;
using System.Xml;
/// <summary>
/// Summary description for ChatEngine
/// </summary>
public class ChatEngine
{
    //public ChatEngine()
    //{
    //    //
    //    // TODO: Add constructor logic here
    //    //
    //}
    //string xmlFile = System.Web.HttpContext.Current.Server.MapPath("../view/chat.xml").ToString();
    ////static protected ArrayList pArray = new ArrayList();
    //////[AjaxPro.AjaxMethod]
    //////public void AddMessage(string sUser, string sMsg)
    //////{
    //////    bSmileys clsSmiley = new bSmileys();
    //////    DataTable dtb = clsSmiley.GetAll().Tables[0];
    //////    string output = sMsg;
    //////    for (int i = 0; i < dtb.Rows.Count; i++)
    //////    {
    //////        if (sMsg.Contains(dtb.Rows[i]["Code"].ToString()))
    //////            output = sMsg.Replace(dtb.Rows[i]["Code"].ToString(), "<img src='../images1/emoticons/" + dtb.Rows[i]["Icon"].ToString() + "' boder='0' />");
    //////    }
    //////    string sAddText = "<b>" + sUser + " :" + "</b>" + output;
    //////    pArray.Add(sAddText);

    //////    if (pArray.Count > 300)
    //////    {
    //////        pArray.RemoveRange(0, 10);
    //////    }
    //////    //InsertNewNode(sAddText);
    //////}

    //////[AjaxPro.AjaxMethod]
    //////public string GetAllMessages()
    //////{
    //////    string sResponse = "";

    //////    for (int i = 0; i < pArray.Count; i++)
    //////    {
    //////        sResponse = sResponse + "<br />" + pArray[i].ToString();
    //////    }

    //////    return (sResponse);
    //////}

    ////public static void GetAllMesseagesToGridView(GridView grv)
    ////{
    ////    grv.DataSource = pArray;
    ////    grv.DataBind();
    ////}

    ////public static void Delete(int index)
    ////{
    ////    pArray.RemoveAt(index);
    ////}

    //[AjaxPro.AjaxMethod]
    //public void AddMessage(string sUser, string sMsg)
    //{
    //    bSmileys clsSmiley = new bSmileys();
    //    DataTable dtb = clsSmiley.GetAll().Tables[0];
    //    string output = sMsg;
    //    for (int i = 0; i < dtb.Rows.Count; i++)
    //    {
    //        if (sMsg.Contains(dtb.Rows[i]["Code"].ToString()))
    //            output = sMsg.Replace(dtb.Rows[i]["Code"].ToString(), "<img src='../images1/emoticons/" + dtb.Rows[i]["Icon"].ToString() + "' boder='0' />");
    //    }
    //    string sAddText = "<b>" + sUser + " :" + "</b>" + output;

    //    XmlDocument xmlDocument = new XmlDocument();
    //    xmlDocument.Load(xmlFile);

    //    XmlElement newXmlElement = xmlDocument.CreateElement("ChatBody");
    //    newXmlElement.InnerText = sAddText;
        
    //    XmlNode xmlNode = xmlDocument.LastChild;
    //    xmlNode.InsertAfter(newXmlElement, xmlNode.LastChild);
        
    //    if (xmlDocument.GetElementsByTagName("ChatBody").Count > 300)
    //    {
    //        for (int i = 0; i < 10; i++)
    //        {
    //            xmlDocument.DocumentElement.RemoveChild(xmlDocument.GetElementsByTagName("ChatBody")[0]);
    //        }
    //    }

    //    xmlDocument.Save(xmlFile);
    //}
    //[AjaxPro.AjaxMethod]
    //public string GetAllMessages()
    //{
    //    string sResponse = "";

    //    XmlDocument xmlDocument = new XmlDocument();
    //    xmlDocument.Load(xmlFile);

    //    XmlNodeList xmlNodeList = xmlDocument.GetElementsByTagName("ChatBody");
    //    foreach (XmlNode xmlNode in xmlNodeList)
    //    {
    //        if (xmlNode.InnerText != String.Empty)
    //        {
    //            sResponse += "<span style=\'margin:15px 0 15px 0\'>"+xmlNode.InnerText + "</span><br />";
    //        }
    //    }
    //    return sResponse;
    //}
}
